//
//  ContactEditController.m
//  sqlite
//
//  Created by hoho on 14-11-9.
//  Copyright (c) 2014年 hoho. All rights reserved.
//

#import "ContactEditController.h"
#import "Contact.h"

@interface ContactEditController ()

@end

@implementation ContactEditController {
    Contact *contact;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    contact = [[Contact alloc]init];
    
    if(_peopleInfoId != -1) {
        
        NSArray *peopleInfo = [contact findOne:_peopleInfoId];
        _contactNameInput.text = [[peopleInfo objectAtIndex:0]objectForKey:@"contact_name"];
        _phoneNumberInput.text = [[peopleInfo objectAtIndex:0]objectForKey:@"phone_number"];

    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)saveContact:(id)sender {
    long long result =[contact save:_peopleInfoId :_contactNameInput.text :_phoneNumberInput.text];
    if(result > 0) {
        [self.delegate editWasFinished];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (IBAction)endEditing:(id)sender {
    [self.view endEditing:YES];
}

@end
